<?php

namespace App\Services\AddProductCloud;

use App\Models\Product;
use App\Models\User;
use Illuminate\Support\Collection;
use App\Supports\Order\WdtClient;

class AddProductCloud
{
	protected Product $product;

	protected array $pendingCacheIds = [];

	public function __construct(Product $product)
	{
		$this->product = $product;
	}

	public function apply()
	{

		$product = $this->product;
		$c = new WdtClient();
		$c->sid = env('WANGDIAN_SID');
		$c->appkey = env('WANGDIAN_APP_KEY');
		$c->appsecret = env('WANGDIAN_APP_SECRET');
		$c->gatewayUrl = 'https://sandbox.wangdian.cn/openapi2/goods_push.php';
		
		$goods_list[] =  array
		(
			"goods_no" => 'no_321',
			"goods_type" => 1,
			"goods_name" => $product->title,
			"spec_list" => array ( array(
		        "spec_no" => "ghs_321",
		        "spec_code" => "test001_01",
		        "barcode" => "test001",
		        "spec_name" => "test",
		        "lowest_price" => 1,
		        "img_url" => 'http://baidu.com',
		        "retail_price" => 1,
		        "wholesale_price" => 1,
		        "member_price" => 1,
		        "market_price" => 1,
		        "sale_score" => 1,
		        "pack_score" => 1,
		        "pick_score" => 1,
				)
			)
		);

		//dd($goods_list);
		$c->putApiParam('goods_list', json_encode($goods_list), JSON_UNESCAPED_UNICODE);
		$json = $c->wdtOpenApi();
		dd(json_decode($json,true));
	}
}
